package com.ziyun.job.modules.job.task.order;

import com.baomidou.mybatisplus.plugins.Page;
import com.ziyun.erp.modules.order.entity.ErpOrderEntity;
import com.ziyun.erp.modules.order.entity.OrderInfoEntity;
import com.ziyun.erp.modules.order.service.ErpOrderService;
import com.ziyun.erp.modules.order.service.OrderInfoService;
import io.renren.common.utils.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author guizhao
 * @Description: 紫云网订单 确认收货
 * @date 2018-09-03 16:07
 */
@Component("confirmZiyunOrderReciveTask")
public class ConfirmZiyunOrderReciveTask {

    /**
     * 日志
     */
    private  static  Logger logger = LoggerFactory.getLogger(ConfirmZiyunOrderReciveTask.class);

    @Autowired
    private OrderInfoService orderInfoService;

    @Autowired
    private ErpOrderService erpOrderService;

    /**
     * 紫云网订单 确认收货
     * @param promotionType 订单类型，默认 normal
     */
    public void confirmZiyunOrderRecive(String promotionType){
        if(StringUtil.isEmpty(promotionType)){
            promotionType = "normal";
        }

        // 当前页数
        int currentPage = 1;

        Page<OrderInfoEntity> page = new Page<>(currentPage,50);
        // 查询 紫云网已发货未收货订单
        Page<OrderInfoEntity> list = orderInfoService.selectNotSendConfirmPage(page);

        // 总页数
        int totalPages = list.getPages();
        do {
            logger.info("紫云网已发货未收货订单---订单数量：" +list.getTotal()+"---每页订单数：50---总页数："+totalPages+"---当前页数："+currentPage);
            if(list != null && list.getTotal() > 0){
                logger.info(""+list.getRecords());
                orderInfoService.finishZiyunOrder(list.getRecords());
            }
            currentPage++;
            if(currentPage <= totalPages){
                page = new Page<>(1,50);
                list = orderInfoService.selectNotSendConfirmPage(page);
            }
        }while (currentPage < totalPages);

        logger.info("紫云网已发货未收货订单确认完成");
    }


}
